﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SCRUM.Core.DAO;
using SCRUM.Core.BusinessObjects;

/// <summary>
/// Usercontrol for selectiong a widget type
/// </summary>
public partial class WidgetTypeSelection : ObjectSelection
{
    protected override WebControl GetWebControl()
    {
        return this.DropDownListWidgetTypes;
    }
    protected override Label GetLabel()
    {
        return this.LabelWidgetTypes;
    }

    /// <summary>
    /// Gets the selected role.
    /// </summary>
    /// <value>The selected role.</value>
    public int SelectedWidgetTypeID
    {
        get
        {
            return Int32.Parse(this.DropDownListWidgetTypes.SelectedValue);
        }
    }

    /// <summary>
    /// Enables disables AutoPostBack for this control
    /// </summary>
    /// <value><c>true</c> if [auto post back]; otherwise, <c>false</c>.</value>
    public bool AutoPostBack
    {
        get { return this.DropDownListWidgetTypes.AutoPostBack; }
        set { this.DropDownListWidgetTypes.AutoPostBack = value; }
    }

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        DataBind();
    }

    /// <summary>
    /// Binds a data source to the invoked server control and all its child controls.
    /// </summary>
    public override void  DataBind()
    {
        base.DataBind();
        //DropDownListWidgetTypes.DataSource = DAORole.GetAllRoles();
        DropDownListWidgetTypes.DataSource = DAOWidgetType.GetAllWidgetTypes();
        DropDownListWidgetTypes.DataTextField = "Name";
        DropDownListWidgetTypes.DataValueField = "ID";
        DropDownListWidgetTypes.DataBind();        
        if (this.IsFilter)
        {
            string top = (string)GetGlobalResourceObject("Filters", "AnyWidget");
            DropDownListWidgetTypes.Items.Insert(0, new ListItem(top, "-1"));
        }
    }

    /// <summary>
    /// Clears the roles.
    /// </summary>
    public void Clear()
    {
        DropDownListWidgetTypes.SelectedIndex = 0;
    }
}
